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§
Source§impl PypiRegistry
impl PypiRegistry
Sourcepub 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.
Sourcepub 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());Sourcepub 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());Sourcepub 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 implementedSourcepub 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§
Source§impl Clone for PypiRegistry
impl Clone for PypiRegistry
Source§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 moreSource§impl PackageRegistry for PypiRegistry
impl PackageRegistry for PypiRegistry
Source§type Version = PypiVersion
type Version = PypiVersion
Source§type Metadata = PypiPackage
type Metadata = PypiPackage
Source§type VersionReq = String
type VersionReq = String
Source§fn get_versions<'life0, 'life1, 'async_trait>(
&'life0 self,
name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<<PypiRegistry as PackageRegistry>::Version>, DepsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
PypiRegistry: 'async_trait,
fn get_versions<'life0, 'life1, 'async_trait>(
&'life0 self,
name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<<PypiRegistry as PackageRegistry>::Version>, DepsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
PypiRegistry: 'async_trait,
Source§fn get_latest_matching<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
name: &'life1 str,
req: &'life2 <PypiRegistry as PackageRegistry>::VersionReq,
) -> Pin<Box<dyn Future<Output = Result<Option<<PypiRegistry as PackageRegistry>::Version>, DepsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
PypiRegistry: 'async_trait,
fn get_latest_matching<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
name: &'life1 str,
req: &'life2 <PypiRegistry as PackageRegistry>::VersionReq,
) -> Pin<Box<dyn Future<Output = Result<Option<<PypiRegistry as PackageRegistry>::Version>, DepsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
PypiRegistry: 'async_trait,
Source§fn search<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<<PypiRegistry as PackageRegistry>::Metadata>, DepsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
PypiRegistry: 'async_trait,
fn search<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<<PypiRegistry as PackageRegistry>::Metadata>, DepsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
PypiRegistry: 'async_trait,
Source§impl Registry for PypiRegistry
impl Registry for PypiRegistry
Source§fn get_versions<'life0, 'life1, 'async_trait>(
&'life0 self,
name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<Box<dyn Version>>, DepsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
PypiRegistry: 'async_trait,
fn get_versions<'life0, 'life1, 'async_trait>(
&'life0 self,
name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<Box<dyn Version>>, DepsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
PypiRegistry: 'async_trait,
Source§fn get_latest_matching<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
name: &'life1 str,
req: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Box<dyn Version>>, DepsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
PypiRegistry: 'async_trait,
fn get_latest_matching<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
name: &'life1 str,
req: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Box<dyn Version>>, DepsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
PypiRegistry: 'async_trait,
Source§fn search<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<Box<dyn Metadata>>, DepsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
PypiRegistry: 'async_trait,
fn search<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<Box<dyn Metadata>>, DepsError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
PypiRegistry: 'async_trait,
Source§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