Struct PypiRegistry
pub struct PypiRegistry { /* private fields */ }Expand description
Client for interacting with the PyPI registry.
Uses the PyPI JSON API for package metadata. All requests are cached via the provided HttpCache.
§Examples
let cache = Arc::new(HttpCache::new());
let registry = PypiRegistry::new(cache);
let versions = registry.get_versions("requests").await.unwrap();
assert!(!versions.is_empty());Implementations§
§impl PypiRegistry
impl PypiRegistry
pub const fn new(cache: Arc<HttpCache>) -> PypiRegistry
pub const fn new(cache: Arc<HttpCache>) -> PypiRegistry
Creates a new PyPI registry client with the given HTTP cache.
pub async fn get_versions(
&self,
name: &str,
) -> Result<Vec<PypiVersion>, PypiError>
pub async fn get_versions( &self, name: &str, ) -> Result<Vec<PypiVersion>, PypiError>
Fetches all versions for a package from PyPI.
Returns versions sorted newest-first. Filters out yanked versions by default.
§Errors
Returns an error if:
- HTTP request fails
- Response body is invalid UTF-8
- JSON parsing fails
- Package does not exist
§Examples
let cache = Arc::new(HttpCache::new());
let registry = PypiRegistry::new(cache);
let versions = registry.get_versions("flask").await.unwrap();
assert!(!versions.is_empty());pub async fn get_latest_matching(
&self,
name: &str,
req_str: &str,
) -> Result<Option<PypiVersion>, PypiError>
pub async fn get_latest_matching( &self, name: &str, req_str: &str, ) -> Result<Option<PypiVersion>, PypiError>
Finds the latest version matching the given PEP 440 version specifier.
Only returns non-yanked, non-prerelease versions by default.
§Errors
Returns an error if:
- HTTP request fails
- Package does not exist
- Version specifier is invalid
§Examples
let cache = Arc::new(HttpCache::new());
let registry = PypiRegistry::new(cache);
let latest = registry.get_latest_matching("flask", ">=3.0,<4.0").await.unwrap();
assert!(latest.is_some());pub async fn search(
&self,
_query: &str,
_limit: usize,
) -> Result<Vec<PypiPackage>, PypiError>
pub async fn search( &self, _query: &str, _limit: usize, ) -> Result<Vec<PypiPackage>, PypiError>
Searches for packages by name/keywords.
Note: PyPI does not provide an official search API, so this returns an empty result for now. Future implementation could use third-party search services or scraping.
§Errors
Currently always returns Ok with empty vector.
§Examples
let cache = Arc::new(HttpCache::new());
let registry = PypiRegistry::new(cache);
let results = registry.search("flask", 10).await.unwrap();
// Currently returns empty, to be implementedpub async fn get_package_metadata(
&self,
name: &str,
) -> Result<PypiPackage, PypiError>
pub async fn get_package_metadata( &self, name: &str, ) -> Result<PypiPackage, PypiError>
Fetches package metadata including description and project URLs.
§Errors
Returns an error if:
- HTTP request fails
- Package does not exist
- JSON parsing fails
Trait Implementations§
§impl Clone for PypiRegistry
impl Clone for PypiRegistry
§fn clone(&self) -> PypiRegistry
fn clone(&self) -> PypiRegistry
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Registry for PypiRegistry
impl Registry for PypiRegistry
§fn get_versions<'a>(
&'a self,
name: &'a str,
) -> Pin<Box<dyn Future<Output = Result<Vec<Box<dyn Version>>, DepsError>> + Send + 'a>>
fn get_versions<'a>( &'a self, name: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Vec<Box<dyn Version>>, DepsError>> + Send + 'a>>
§fn get_latest_matching<'a>(
&'a self,
name: &'a str,
req: &'a str,
) -> Pin<Box<dyn Future<Output = Result<Option<Box<dyn Version>>, DepsError>> + Send + 'a>>
fn get_latest_matching<'a>( &'a self, name: &'a str, req: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Option<Box<dyn Version>>, DepsError>> + Send + 'a>>
§fn search<'a>(
&'a self,
query: &'a str,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<Box<dyn Metadata>>, DepsError>> + Send + 'a>>
fn search<'a>( &'a self, query: &'a str, limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<Box<dyn Metadata>>, DepsError>> + Send + 'a>>
§fn package_url(&self, name: &str) -> String
fn package_url(&self, name: &str) -> String
Auto Trait Implementations§
impl Freeze for PypiRegistry
impl !RefUnwindSafe for PypiRegistry
impl Send for PypiRegistry
impl Sync for PypiRegistry
impl Unpin for PypiRegistry
impl !UnwindSafe for PypiRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more